/* --------------------------------------

A2_HoldingsRegressions.do

by: Kristy A.E. Jansen

This do-file: Main regression analysis Jansen (2024) -- part 1
	1. Table 2+IA2+IA3+IA13
	2. Table 3+IA14
	3. Table 4+IA15
	4. Table IA16

-------------------------------------- */

/* Initialization */
clear all
set more off
capture log clear _all

global root "~/RFS_replication" // *** NEED TO CHANGE THIS TO CORRECT FILE PATH ***
global main_data $root/Data

/* Stata Packages */
*ssc install estout
*ssc install ftools
*ssc install reghdfe

/* Load Data */
use "$main_data/pseudo_data_part1.dta", clear

/* Set panel */
xtset fund yq
sort fund yq

/* Comment out to create Table IA13, IA14, and IA15 */
*drop if yq>tq(2014q3)

/* -------------------------  Holdings Regressions ------------------------- */ 

display("Table 2: Long-term bond holdings and the regulatory discount curve") // same code to create Tables IA2 + IA3 + IA13

estimates clear 
qui: reghdfe frac_mat_bucket_fundyq_7 c.dummyUFR##c.liab_dur_2011q2 ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR dummyIClife dummyPF, noabsorb cluster(fund)
estimates store model1

qui: reghdfe frac_mat_bucket_fundyq_7 c.dummyUFR#c.liab_dur_2011q2 ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund)
estimates store model2

qui: reghdfe frac_mat_close_20_fundyq c.dummyUFR##c.liab_dur_2011q2 ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR dummyIClife dummyPF, noabsorb cluster(fund)
estimates store model3

qui: reghdfe frac_mat_close_20_fundyq c.dummyUFR#c.liab_dur_2011q2 ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund) 
estimates store model4

qui: reghdfe frac_short_fundyq c.dummyUFR##c.liab_dur_2011q2 ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR dummyIClife dummyPF, noabsorb cluster(fund)
estimates store model5

qui: reghdfe frac_short_fundyq c.dummyUFR#c.liab_dur_2011q2 ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund) 
estimates store model6

esttab model*, ar2(2) b(3) t(2) star(* 0.10 ** 0.05 *** 0.01) nogaps brackets ///
varwidth(45) mlabels(30-year 30-year 20-year 20-year short-term short-term)


display("Table 3: Asset allocation and the regulatory discount curve") // same code to create Table IA14

estimates clear
qui: reghdfe frac_stocks_fundyq c.liab_dur_2011q2#c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr  L.logsize L.vol_FR, absorb(fund yq) cluster(fund)   
estimates store model1

qui: reghdfe frac_corp_fundyq c.liab_dur_2011q2#c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund)     
estimates store model2

qui: reghdfe CreditRatingCORP_nominal c.liab_dur_2011q2#c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund)     
estimates store model3

qui: reghdfe frac_gov_fundyq c.liab_dur_2011q2#c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund)     
estimates store model4

qui: reghdfe CreditRatingGOV_nominal c.liab_dur_2011q2#c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr  L.logsize L.vol_FR, absorb(fund yq) cluster(fund)     
estimates store model5

qui: reghdfe frac_HY_fundyq c.liab_dur_2011q2#c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr  L.logsize L.vol_FR, absorb(fund yq) cluster(fund)     
estimates store model6

esttab model*, ar2(2) b(3) t(2) star(* 0.10 ** 0.05 *** 0.01) nogaps brackets ///
varwidth(45) mlabels(stocks corporate credit-corp government credit-gov HY-gov)


display("Table 4: Long-term bond holdings and constraints") // same code to create Table IA15

estimates clear 
qui: reghdfe frac_mat_bucket_fundyq_7 c.liab_dur_2011q2##c.gap_fr_2011q2##c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR dummyIClife dummyPF , noabsorb cluster(fund)
estimates store model1

qui: reghdfe frac_mat_bucket_fundyq_7 c.liab_dur_2011q2#c.gap_fr_2011q2#c.dummyUFR ///
c.liab_dur_2011q2#c.dummyUFR c.gap_fr_2011q2#c.dummyUFR L.liab_dur  ///
L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund) 
estimates store model2

qui: reghdfe frac_mat_close_20_fundyq c.liab_dur_2011q2##c.gap_fr_2011q2##c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR dummyIClife dummyPF, noabsorb cluster(fund)
estimates store model3

qui: reghdfe frac_mat_close_20_fundyq c.liab_dur_2011q2#c.gap_fr_2011q2#c.dummyUFR ///
c.liab_dur_2011q2#c.dummyUFR c.gap_fr_2011q2#c.dummyUFR L.liab_dur  ///
L.inverse_fr c.dummyPF#c.L.inverse_fr L.logsize L.vol_FR, absorb(fund yq) cluster(fund) 
estimates store model4

qui: reghdfe frac_short_fundyq c.liab_dur_2011q2##c.gap_fr_2011q2##c.dummyUFR ///
L.liab_dur L.inverse_fr c.dummyPF#c.L.inverse_fr  L.logsize L.vol_FR dummyIClife dummyPF, noabsorb cluster(fund)
estimates store model5

qui: reghdfe frac_short_fundyq c.liab_dur_2011q2#c.gap_fr_2011q2#c.dummyUFR ///
c.liab_dur_2011q2#c.dummyUFR c.gap_fr_2011q2#c.dummyUFR L.liab_dur  ///
L.inverse_fr c.dummyPF#c.L.inverse_fr  L.logsize L.vol_FR, absorb(fund yq) cluster(fund) 
estimates store model6

esttab model*, ar2(2) b(3) t(2) star(* 0.10 ** 0.05 *** 0.01) nogaps brackets ///
varwidth(45) mlabels(30-year 30-year 20-year 20-year short-term short-term)


/* -------------------------  Alternative Specifications ------------------------- */ 

display("Table IA16: Long-term bond holdings and the regulatory discount curve - cross-sectional regressions") 

/* Average over entire period pre and post */
preserve
foreach var of varlist liab_dur inverse_fr logsize frac_mat_bucket_fundyq_7 ///
frac_mat_close_20_fundyq frac_short_fundyq {
egen av_`var' = mean(`var'), by(dummyUFR fund)
}

bysort fund: egen mean_liab_dur_2011q2 = mean(liab_dur_2011q2)
drop liab_dur_2011q2
rename mean_liab_dur_2011q2 liab_dur_2011q2

keep fund av_* dummyUFR liab_dur_2011q2 dummyPF dummyIClife
duplicates drop

xtset fund dummyUFR
estimates clear 
qui: reghdfe av_frac_mat_bucket_fundyq_7 dummyUFR c.dummyUFR#c.liab_dur_2011q2,    ///
vce(robust) absorb(fund)
estimates store model1
qui: reghdfe av_frac_mat_close_20_fundyq dummyUFR c.dummyUFR#c.liab_dur_2011q2,  ///
vce(robust) absorb(fund)
estimates store model2
qui: reghdfe av_frac_short_fundyq dummyUFR c.dummyUFR#c.liab_dur_2011q2,  ///
vce(robust) absorb(fund)
estimates store model3

esttab model*, ar2(4) b(4) t(2) star(* 0.10 ** 0.05 *** 0.01) nogaps brackets /// 
varwidth(30) mlabels(30-year 20-year short-term)
restore

/* Keep quarter only before and after */
preserve
drop if yq>tq(2012q3) | yq<tq(2012q1)

foreach var of varlist liab_dur inverse_fr logsize frac_mat_bucket_fundyq_7 ///
frac_mat_close_20_fundyq frac_short_fundyq {
egen average_`var'=mean(`var'), by(dummyUFR fund)
}

bysort fund: egen mean_liab_dur_2011q2 = mean(liab_dur_2011q2)
drop liab_dur_2011q2
rename mean_liab_dur_2011q2 liab_dur_2011q2

keep fund average_* dummyUFR liab_dur_2011q2 dummyPF dummyIClife
duplicates drop

estimates clear 
qui: reghdfe average_frac_mat_bucket_fundyq_7 dummyUFR c.dummyUFR#c.liab_dur_2011q2, ///
vce(robust) absorb(fund)
estimates store model1
qui: reghdfe average_frac_mat_close_20_fundyq dummyUFR c.dummyUFR#c.liab_dur_2011q2, ///
vce(robust) absorb(fund)
estimates store model2
qui: reghdfe average_frac_short_fundyq dummyUFR c.dummyUFR#c.liab_dur_2011q2,  ///
vce(robust) absorb(fund)
estimates store model3

esttab model*, ar2(4) b(4) t(2) star(* 0.10 ** 0.05 *** 0.01) nogaps brackets /// 
varwidth(30) mlabels(30-year 20-year short-term)
restore


